{% extends "base.html" %}

{% block title %}登录页面{% endblock %}

{% block content %}
<form action="/login" method="post" class="login-form">
    <div class="input-group">
        <input type="text" name="username" placeholder="请输入用户名：" id="username" required>
        <i class="fas fa-user"></i>
    </div>
    <div class="input-group">
        <input type="password" name="password" placeholder="请输入密码" id="password" required>
        <i class="fas fa-lock"></i>
    </div>
    <input type="submit" value="登录">
    <a href="/index_register">注册</a>
</form>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<script>
    document.addEventListener('DOMContentLoaded', function () {
        const form = document.querySelector('.login-form');
        form.addEventListener('submit', function (e) {
            const username = document.getElementById('username').value.trim();
            const password = document.getElementById('password').value.trim();

            if (username === "") {
                e.preventDefault();
                alert('用户名不能为空，请填写完整！');
            } else if (password === "") {
                e.preventDefault();
                alert('密码不能为空，请填写完整！');
            }
        });
    });
</script>
{% endblock %}